﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text
using System.Data;
using System.Data.SqlClient;
using HotelManager.Model;
using HotelManager.Core;

namespace HotelManager.DataAccess
{
    class SuDungDvAccess
    {
        dbConnection db = new dbConnection();
        public DataTable layToanboTTDichvu()
    {
        return db.executeSelectProcedureQueryNonParameter("select_sudungdv");

}
    //
    public DataView timkiemMadv(string Madv)
    {
        DataView dataWiew = layToanboTTDichvu().DefaultView;
        dataWiew.RowFilter = string.Format("Ma_dichvu like '%{0}%'",Madv);
        return dataWiew;
    }
        // 
    public DataView timkiemTendv(string Tendv)
    {
        DataView dataWiew = layToanboTTDichvu().DefaultView;
        dataWiew.RowFilter = string.Format("Ten_dichvu like '%{0}%'",Tendv);
        return dataWiew;
    }
        //
    public DataView timkiemdichvutheoma(string madv)
    {
        SqlParameter[] listParam = new SqlParameter[1]
        SqlParameter ma = new SqlParameter("@Ma_dv",SqlDbType.Char,10);
        ma.Value = madv;
        listParam[0] = ma;
        return db.executeSelectProcedureQuery("timkiem_dichvu",listParam);
    }
        //
        public int themDichVu(DichVu dv)
        {
            if ((timkiemdichvutheoma(dv.MaDV1).Rows.Cout >0))
                return 0;
            else
            {
                SqlParameter[] listParam = new SqlParameter[6];
                SqlParameter madv = new SqlParameter("@Ma_dv",SqlDbType.Char,10);
                madv.Value = dv.MaDV1;
                listParam[0] = madv;
                listParam[1] = new SqlParameter("@Ten_dv",dv.TenDV1);
                listParam[2] = new SqlParameter("@Gia_dv",dv.Gia1);
                listParam[3] = new SqlParameter("@Ma_phong",dv.MaPhong1);
                listParam[4] = new SqlParameter("@Ma_so",dv.MaSo1);
                listParam[5] = new SqlParameter("@N_ql",dv.NQL1);
                db.executeInsertProcedureQuery("insert_dichvu",listParam);
                return 1;
            }
        }
        //
        public int suaDichVu(DichVu dv)
        {
            if ((timkiemdichvutheoma(dv.MaDV1) == null))
                return 0;
            else
            {
                SqlParameter[] listParam = new SqlParameter[6];
                SqlParameter madv = new SqlParameter("@Ma_dv",SqlDbType.Char,10);
                madv.Value = dv.MaDV1;
                listParam[1] = new SqlParameter("@Ten_dv",dv.TenDV1);
                listParam[2] = new SqlParameter("@Gia_dv",dv.Gia1);
                listParam[3] = new SqlParameter("@Ma_phong",dv.MaPhong1);
                listParam[4] = new SqlParameter("@Ma_so",dv.MaSo1);
                listParam[5] = new SqlParameter("@N_ql",dv.NQL1);
                db.executeInsertProcedureQuery("insert_dichvu",listParam);
                return 1;
            }
        }
        //
        public int xoadv(DichVu dv)
        {
            if ((timkiemdichvutheoma(dv.MaDV1) == null))
                return 0;
            else
            {
                SqlParameter[] listParam = new SqlParameter[1];
                SqlParameter madv = new SqlParameter("@Ma_dv",SqlDbType.Char, 10);
                madv.Value = dv.MaDV1;
                listParam[0] = madv;
                db.executeDeleteProcedureQuery("delete_dichvu",listParam);
                return 1;
            }
        }



